#!/bin/bash
# why: shutdown the hyper threading . usage  sh <sc name> offline
CPUMAX=128

if [ "$1" = "online" ]; then
        echo "Onlining:"
        for((ii=0;ii<$CPUMAX;ii++)); do
                test -e /sys/devices/system/cpu/cpu$ii/online || continue
                echo 1 > /sys/devices/system/cpu/cpu$ii/online
                echo -e "\tCPU $ii"
        done
elif [ "$1" = "offline" ]; then
        MAXCPUNO=0
        for((ii=4;ii<$CPUMAX;ii++)); do
                test -e /sys/devices/system/cpu/cpu$ii/online || continue
                if [ $ii -gt $MAXCPUNO ]; then
                        MAXCPUNO=$ii
                fi
        done
        ((MAXCPUNO++))
        ((MAXCPUNO=MAXCPUNO/2))

        echo "Offlining:"
        for((ii=$MAXCPUNO;ii<$CPUMAX;ii++)); do
                test -e /sys/devices/system/cpu/cpu$ii/online || continue
                echo 0 > /sys/devices/system/cpu/cpu$ii/online
                echo -e "\tCPU $ii"
        done
else
        echo "Usage: $0 [online | offline]"
        exit 1
fi
